﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    /// Queue扩展类
    /// </summary>
    public static class QueueEx
    {
        /// <summary>
        /// 深度从队列中取出一项
        /// </summary>
        /// <typeparam name="T">队列集合项类型</typeparam>
        /// <param name="queue">队列</param>
        /// <param name="item">输出项</param>
        /// <returns>出队列结果[true:成功;false:失败]</returns>
        public static bool TryDequeue<T>(this Queue<T> queue, out T item)
        {
            if (queue.Count > 0)
            {
                item = queue.Dequeue();
                return true;
            }
            else
            {
                item = default(T);
                return false;
            }
        }
    }
}
